home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / InsertCoffees.java < prev    next >
Text File  |  1998-06-30  |  2KB  |  70 lines

  1.  
  2. import java.sql.*;
  3.      
  4. public class InsertCoffees {
  5.  
  6.     public static void main(String args[]) {
  7.           
  8.       /****************
  9.       DataTable dt = new JDBCAdapter(
  10.             "jdbc:sybase://dbtest:1455/spring",
  11.             "SELECT * FROM test",
  12.             "connect.sybase.SybaseDriver",
  13.             "guest",
  14.             "trustworthy");
  15.       *******************************/
  16.  
  17.         String url = "jdbc:sybase://dbtest:1455/spring";
  18.         Connection con;
  19.         Statement stmt;
  20.         String query = "select COF_NAME, PRICE from COFFEES";
  21.     
  22.         try {
  23.             Class.forName("connect.sybase.SybaseDriver");
  24.     
  25.         } catch(java.lang.ClassNotFoundException e) {
  26.             System.err.print("ClassNotFoundException: "); 
  27.             System.err.println(e.getMessage());
  28.         }
  29.  
  30.         try {
  31.  
  32.             con = DriverManager.getConnection(url, 
  33.                                      "guest", "trustworthy");
  34.     
  35.             stmt = con.createStatement();                            
  36.     
  37.             stmt.executeUpdate("insert into COFFEES " +
  38.                  "values('Colombian', 00101, 7.99, 0, 0)");
  39.     
  40.             stmt.executeUpdate("insert into COFFEES " +
  41.                  "values('French_Roast', 00049, 8.99, 0, 0)");
  42.             
  43.             stmt.executeUpdate("insert into COFFEES " +
  44.                  "values('Espresso', 00150, 9.99, 0, 0)");
  45.     
  46.             stmt.executeUpdate("insert into COFFEES " +
  47.                  "values('Colombian_Decaf', 00101, 8.99, 0, 0)");
  48.     
  49.             stmt.executeUpdate("insert into COFFEES " +
  50.                  "values('French_Roast_Decaf', 00049, 9.99, 0, 0)");
  51.     
  52.             ResultSet rs = stmt.executeQuery(query);
  53.     
  54.             System.out.println("Coffee Break Coffees and Prices:");
  55.             while (rs.next()) {
  56.                 String s = rs.getString("COF_NAME");
  57.                 float f = rs.getFloat("PRICE");
  58.                 System.out.println(s + "   " + f);
  59.             }
  60.     
  61.             stmt.close();
  62.             con.close();
  63.     
  64.         } catch(SQLException ex) {
  65.             System.err.println("SQLException: " + ex.getMessage());
  66.         }
  67.     }
  68. }
  69.  
  70.